/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pgentity;

import db.DBContext;
import db.PGKeys;
import db.RedisKey;
import pgentity.redis.hash.DataHash;
import share.PGHelper;
import share.PGMacro;

/**
 *
 * @author Salm
 */
public class Minigame extends DataHash {
    private final String uid;

    private Minigame(String uid) {
        super(key(uid));
        this.uid = uid;
    }
    
    public static Minigame getMinigame(String uid)
    {
        return new Minigame(uid);
    }
    
    public static void destroy(String uid)
    {
        DBContext.Redis().del(key(uid));
    }
    
    public static RedisKey key(String uid)
    {
        return User.redisKey(uid).getChild(PGKeys.FD_MINIGAME);
    }

    public String getUid() {
        return uid;
    }
    
    public int getTurn()
    {
        return PGHelper.toInt(getData(PGMacro.MNG_TURN));
    }
    
    public void incTurn(int inc)
    {
        incData(PGMacro.MNG_TURN, inc);
    }
    
    public void decTurn()
    {
        incData(PGMacro.MNG_TURN, -1);
    }
}
